﻿Public Class frmCajaListado

    Private Sub frmCajaListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        fechaInicio.Value = DateTime.Now
        fechaFin.Value = DateTime.Now
        dgCompras.AutoGenerateColumns = False
        CargarCaja()
    End Sub

    Dim controller As New ControllerSigeco.controller_compras()
    Dim controllerVta As New ControllerSigeco.controller_ventas()

    Private m_frmCompras As frmComprasGastos

    Public Property frmCompras() As frmComprasGastos
        Get
            Return m_frmCompras
        End Get
        Set(ByVal value As frmComprasGastos)
            m_frmCompras = value
        End Set
    End Property

    Private Sub CargarCaja()

        Dim dt As New DataTable
        dt = controller.get_Caja_All(oiml.dbConn, fechaInicio.Value, fechaFin.Value, oiml.isNumeric(txtNroComprobante.Text))
        dgCompras.DataSource = dt

    End Sub


    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            If dgCompras.SelectedRows.Count > 0 Then

                Dim cod As New Integer
                cod = dgCompras.SelectedRows(0).Cells(0).Value

                If frmCompras Is Nothing Then

                    frmCompras = New frmComprasGastos
                    frmCompras.codCajaExterno = cod
                    frmCompras.codTipoParam = "LISTADO"
                    'If frmClientes.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmCompras.ShowDialog()

                    CargarCaja()

                    frmCompras.Dispose()
                    frmCompras = Nothing
                    'End If
                Else
                    frmCompras.codCajaExterno = cod
                    frmCompras.codTipoParam = "LISTADO"
                    frmCompras.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarCaja()
    End Sub

    Private Sub dgCompras_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgCompras.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgCompras_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgCompras.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub

    Private m_frmBusProveedor As frmProveedorBuscador
    Public Property frmBusProveedor() As frmProveedorBuscador
        Get
            Return m_frmBusProveedor
        End Get
        Set(ByVal value As frmProveedorBuscador)
            m_frmBusProveedor = value
        End Set
    End Property

    Private m_frmReporte As frmReportes
    Public Property frmRpts() As frmReportes
        Get
            Return m_frmReporte
        End Get
        Set(ByVal value As frmReportes)
            m_frmReporte = value
        End Set
    End Property

    Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprimir.Click

        'If frmRpts Is Nothing Then
        '    frmRpts = New frmReportes
        '    'frmRpts.MdiParent = Me
        '    frmRpts.tipo_Reporte = "COMPRAS"
        '    frmRpts.datos_Reporte = CType(dgCompras.DataSource, DataTable).Copy
        '    frmRpts.ShowDialog()
        'Else

        '    If Not frmRpts.Visible Then
        '        frmRpts = New frmReportes()
        '        'frmRpts.MdiParent = Me
        '        frmRpts.tipo_Reporte = "COMPRAS"
        '        frmRpts.datos_Reporte = CType(dgCompras.DataSource, DataTable).Copy
        '        frmRpts.ShowDialog()
        '    Else
        '        frmRpts.tipo_Reporte = "COMPRAS"
        '        frmRpts.datos_Reporte = CType(dgCompras.DataSource, DataTable).Copy
        '        frmRpts.Select()
        '        frmRpts.Activate()
        '    End If

        'End If


    End Sub

End Class